package com.example.villagedevelop.generator.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.villagedevelop.generator.entity.Case0;
import com.example.villagedevelop.generator.entity.Policy;
import com.example.villagedevelop.generator.entity.PolicyVO;
import com.example.villagedevelop.generator.mapper.PolicyMapper;
import com.example.villagedevelop.generator.service.PolicyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import org.springframework.stereotype.Controller;

import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author villagedevelop
 * @since 2021-11-13
 */
@RestController
@RequestMapping("/policy")
public class PolicyController {
    @Autowired
    PolicyMapper mapper;
    @Autowired
    PolicyService policyService;


    //返回所有数据（不分页）,未返回VO，不包括照片
    @GetMapping("/visitall")
    public List<Policy> findAll(){
        return policyService.list();
    }
    
    //分页查询返回数据
    @GetMapping("/visit/{page}")
    public List<PolicyVO> findList(@PathVariable("page") int current){
//        Page<Policy> page = new Page<>(current,5);
//        IPage<Policy> result = mapper.selectPage(page,null);
//        List<Policy> list = result.getRecords();
//        return list;
        return policyService.findPolicyVOByPage(current);
    }

    @PostMapping("/save")
    public void save(@RequestBody PolicyVO policyVO){
        policyService.insertPolicyVO(policyVO);
    }

}

